package org.teremail.mailbox;

import java.util.Collection;
import java.util.Map;

import org.teremail.message.Entity;
import org.teremail.message.Message;

/**
 * Data Access Layer object for entities.  Entities are designed to be 
 * immutable, so only save and get methods are provided, no methods for
 * updating will be supplied.
 * 
 * @author Michael Barker.
 *
 */
public interface MessageDAO {

    /**
     * Saves an entity.  Entities are immutable, therefore if an Entity that
     * has already been saved is passed to this method, then nothing will
     * happen.  I.e. an entity will only be written if <code>entity.getId() == 
     * Entity.UNSAVED_VALUE</code>
     * 
     * @param message
     * @return
     */
    Entity save(Entity entity);

    /**
     * Loads a message by id.  This should load all part of the particular
     * message.
     * 
     * @param id
     * @return
     */
    Entity load(String id);

    /**
     * Loads a collection of messages according to message id.  The result
     * should be all of the messages indexed by id.
     * 
     * @param ids
     * @return
     */
    Map<String,Entity> load(Collection<String> ids);

    /**
     * Loads a collection of messages according to message id.  The result
     * should be all of the messages indexed by id.
     * 
     * @param ids
     * @return
     */
    Map<String,Message> loadMessages(Collection<String> ids);

    Message loadMessage(String messageId);
}
